package _interview150;

/**
 * 80. 删除有序数组中的重复项 II
 */
public class No80 {
    public int removeDuplicates(int[] nums) {
        int left = 0;
        int count = 1;
        for (int right = 1; right < nums.length; right++) {
            if (nums[right] == nums[right - 1]) {
                count++;
                if (count <= 2) {
                    int pre = nums[left];
                    nums[++left] = pre;
                }
            } else {
                nums[++left] = nums[right];
                count = 1;
            }
        }
        return left + 1;
    }
}
